<?php

namespace Database\Seeders;

use App\Models\Admin\SysPermission;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;

class SysPermissionSeeder extends Seeder
{
    /**
     * Run the database seeds.
     */
    public function run(): void
    {

        $system = SysPermission::create([
            'name' => '系统管理',
            'path' => '/system',
            'perm' => null,
            'type' => 1,
            'component' => 'Layout',
            'sort' => 1,
            'visible' => 1,
            'icon' => 'system',
            'redirect' => '/system/user'
        ]);


        $user = $system->children()->create([
            'name' => '用户管理',
            'type' => 2,
            'path' => '/user',
            'component' => 'system/user/index',
            'sort' => 1,
            'visible' => 1,
            'icon' => 'user',
            'perm' => null
        ]);

        $user->children()->createMany([
            [
                "name" => "用户新增",
                "type" => 4,
                "path" => "",
                "component" => null,
                "sort" => 1,
                "visible" => 1,
                "icon" => "",
                "redirect" => "",
                "perm" => "sys:user:add",
            ],
            [
                "name" => "用户编辑",
                "type" => 4,
                "path" => "",
                "component" => null,
                "sort" => 2,
                "visible" => 1,
                "icon" => "",
                "redirect" => "",
                "perm" => "sys:user:edit",
            ],
            [
                "name" => "用户删除",
                "type" => 4,
                "path" => "",
                "component" => null,
                "sort" => 3,
                "visible" => 1,
                "icon" => "",
                "redirect" => "",
                "perm" => "sys:user:delete",
            ],
            [
                "name" => "重置密码",
                "type" => 4,
                "path" => "",
                "component" => null,
                "sort" => 4,
                "visible" => 1,
                "icon" => "",
                "redirect" => null,
                "perm" => "sys:user:reset_pwd",
            ]
        ]);

        $role = $system->children()->create([
            "name" => "角色管理",
            "type" => 2,
            "path" => "role",
            "component" => "system/role/index",
            "sort" => 2,
            "visible" => 1,
            "icon" => "role",
            "redirect" => null,
            "perm" => null,
        ]);

        $role->children()->createMany([
            [
                "name" => "角色新增",
                "type" => 4,
                "path" => "",
                "component" => null,
                "sort" => 1,
                "visible" => 1,
                "icon" => "",
                "redirect" => null,
                "perm" => "sys:role:add",
            ],
            [
                "name" => "角色编辑",
                "type" => 4,
                "path" => "",
                "component" => null,
                "sort" => 2,
                "visible" => 1,
                "icon" => "",
                "redirect" => null,
                "perm" => "sys:role:edit",
            ],
            [
                "name" => "角色删除",
                "type" => 4,
                "path" => "",
                "component" => null,
                "sort" => 3,
                "visible" => 1,
                "icon" => "",
                "redirect" => null,
                "perm" => "sys:role:delete",
            ]
        ]);

        $menu = $system->children()->create( [
            "name" => "菜单管理",
            "type" => 2,
            "path" => 2,
            "component" => "system/menu/index",
            "sort" => 3,
            "visible" => 1,
            "icon" => 'menu',
            "redirect" => null,
            "perm" => null,
        ]);

        $menu->children()->createMany([
            [
                "name" => "菜单新增",
                "type" => 4,
                "path" => "",
                "component" => null,
                "sort" => 1,
                "visible" => 1,
                "icon" => "",
                "redirect" => null,
                "perm" => "sys:menu:add",
            ],
            [
                "name" => "菜单编辑",
                "type" => 4,
                "path" => "",
                "component" => null,
                "sort" => 3,
                "visible" => 1,
                "icon" => "",
                "redirect" => null,
                "perm" => "sys:menu:edit",
            ],
            [
                "name" => "菜单删除",
                "type" => 4,
                "path" => "",
                "component" => null,
                "sort" => 3,
                "visible" => 1,
                "icon" => "",
                "redirect" => null,
                "perm" => "sys:menu:delete",
            ]
        ]);


        $dept = $system->children()->create([
            "name" => "部门管理",
            "type" => 2,
            "path" => "dept",
            "component" => "system/dept/index",
            "sort" => 4,
            "visible" => 1,
            "icon" => "tree",
            "redirect" => null,
            "perm" => null,
        ]);

        $dept->children()->createMany([
            [
                "name" => "部门新增",
                "type" => 4,
                "path" => "",
                "component" => null,
                "sort" => 1,
                "visible" => 1,
                "icon" => "",
                "redirect" => null,
                "perm" => "sys:dept:add",
            ],
            [
                "name" => "部门编辑",
                "type" => 4,
                "path" => "",
                "component" => null,
                "sort" => 2,
                "visible" => 1,
                "icon" => "",
                "redirect" => null,
                "perm" => "sys:dept:edit",
            ],
            [
                "name" => "部门删除",
                "type" => 4,
                "path" => "",
                "component" => null,
                "sort" => 3,
                "visible" => 1,
                "icon" => "",
                "redirect" => null,
                "perm" => "sys:dept:delete",
            ]
        ]);

        $dict = $system->children()->create([
            "name" => "字典管理",
            "type" => 2,
            "path" => "dict",
            "component" => "system/dict/index",
            "sort" => 5,
            "visible" => 1,
            "icon" => "dict",
            "redirect" => null,
            "perm" => null,
        ]);

        $dict->children()->createMany([
            [
                "name" => "字典类型新增",
                "type" => 4,
                "path" => "",
                "component" => null,
                "sort" => 1,
                "visible" => 1,
                "icon" => "",
                "redirect" => null,
                "perm" => "sys:dict_type:add",
            ],
            [
                "name" => "字典类型编辑",
                "type" => 4,
                "path" => "",
                "component" => null,
                "sort" => 2,
                "visible" => 1,
                "icon" => "",
                "redirect" => null,
                "perm" => "sys:dict_type:edit",
            ],
            [
                "name" => "字典类型删除",
                "type" => 4,
                "path" => "",
                "component" => null,
                "sort" => 3,
                "visible" => 1,
                "icon" => "",
                "redirect" => null,
                "perm" => "sys:dict_type:delete",
            ],
            [
                "name" => "字典数据新增",
                "type" => 4,
                "path" => "",
                "component" => null,
                "sort" => 4,
                "visible" => 1,
                "icon" => "",
                "redirect" => null,
                "perm" => "sys:dict:add",
            ],
            [
                "name" => "字典数据编辑",
                "type" => 4,
                "path" => "",
                "component" => null,
                "sort" => 5,
                "visible" => 1,
                "icon" => "",
                "redirect" => null,
                "perm" => "sys:dict:edit",
            ],
            [
                "name" => "字典数据删除",
                "type" => 4,
                "path" => "",
                "component" => null,
                "sort" => 6,
                "visible" => 1,
                "icon" => "",
                "redirect" => null,
                "perm" => "sys:dict:delete",
            ]
        ]);


        $multi = SysPermission::create([
            "name" => "多级菜单",
            "type" => 1,
            "path" => "/multi-level",
            "component" => "Layout",
            "sort" => 9,
            "visible" => 1,
            "icon" => "cascader",
            "redirect" => "/multi-level/multi-level1",
            "perm" => null,
        ]);

        $levelTop = $multi->children()->create([
            "name" => "菜单一级",
            "type" => 2,
            "path" => "multi-level1",
            "component" => "demo/multi-level/level1",
            "sort" => 1,
            "visible" => 1,
            "icon" => "",
            "redirect" => "/multi-level/multi-level2",
            "perm" => null,
        ]);

        $levelSecondary = $levelTop->children()->create([
            "name" => "菜单二级",
            "type" => 2,
            "path" => "multi-level2",
            "component" => "demo/multi-level/children/level2",
            "sort" => 1,
            "visible" => 1,
            "icon" => "",
            "redirect" => "/multi-level/multi-level2/multi-level3-1",
            "perm" => null,
        ]);

        $levelSecondary->children()->createMany([
            [
                "name" => "菜单三级-1",
                "type" => 2,
                "path" => "multi-level3-1",
                "component" => "demo/multi-level/children/children/level3-1",
                "sort" => 1,
                "visible" => 1,
                "icon" => "",
                "redirect" => "",
                "perm" => null,
            ],
            [
                "name" => "菜单三级-2",
                "type" => 2,
                "path" => "multi-level3-2",
                "component" => "demo/multi-level/children/children/level3-2",
                "sort" => 2,
                "visible" => 1,
                "icon" => "",
                "redirect" => "",
                "perm" => null,
            ]
        ]);

    }
}
